/**
 * @file cx_timer.h
 * @author Char_X (ziyangwork@163.com)
 * @brief implementation of timer trigger function with hardware independent(By register basic method)
 * @version 1.0
 * @date 2023-03-01 V0.1  Base Functions
 * @date 2023-03-18 V0.2  Added support for timestamp function,use macro CX_LIB_ENABLE_TIMER_TIMESTAMP
 * @date 2023-04-17 V0.3  Modified time stamp function,embedded in cx_timer;abolish cx_timer.Init 's parameter,return 0
 * 
 * @note: Starting hardware timer with calling member function:cx_timer.timerInit(InitHardwareTimer(args), args)
 *        call member function:cx_timer.INT_Handler() in hardware timer interrupt to activate cx_timer
 * 
 * @copyright Copyright (c) 2023
 * 
 */

#ifndef TIMER_H
#define TIMER_H

#ifdef __cplusplus
extern "C" {
#endif

#include "cx_event.h"
#include "cx_typedef.h"

typedef enum trigger_type_enum
{
    TriggerTypeNormal = 0,
    TriggerTypeOneShot = 1,
}trigger_type_enum_t;

#ifndef CX_DISABLE_TIMER_EVENT
typedef struct timer_trigger_event
{
    cx_u32                  gap;
    cx_u32                  trigger_tick;
    trigger_type_enum_t  trigger_type;
    event_t              event;
}timer_trigger_event_t;
#endif

#ifndef CS_DISABLE_SW_TIMER
typedef struct software_timer
{
    cx_u32 gap;
    cx_u32 trigger_tick;
    trigger_type_enum_t trigger_type;
    int (*cb_handler)(void *);
    void *args;
}software_timer_t;
#endif


typedef struct timer_interface
{
    int  (*Init)(void);
    cx_u32  (*getTicks)(void);
    void (*InterruptHandler)(void);
#ifndef CX_DISABLE_TIMER_EVENT
    int  (*addTriggerEvent)(timer_trigger_event_t *);
    int  (*deleteTriggerEvent)(timer_trigger_event_t *);
#endif

#ifndef CX_DISABLE_SW_TIMER
    int  (*regSWTimer)(software_timer_t*);
    int  (*unSWTimer)(software_timer_t*);
#endif

#ifndef CX_LIB_DISABLE_TIMER_TIMESTAMP
    int (*timestamp_init)(unsigned int (*GetTimeCount)(void), unsigned int CountPerTick);
    unsigned int (*getTimeStamp)(void);
#endif

}timer_interface_t;

extern timer_interface_t cx_timer;

#ifdef __cplusplus
}
#endif

#endif
